package com.example.controller;

import com.example.entity.po.Classroom;
import com.example.entity.po.Course;
import com.example.entity.vo.IdClassroom;
import com.example.entity.vo.PlaceClassroom;
import com.example.utils.ResultUtils;
import com.example.service.ClassroomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Controller
@RestController
public class ClassroomController {
    @Autowired
    private ClassroomService classroomService;

    //查找所有教室
    @GetMapping("/ClassroomList")
    public ResultUtils queryClassroom(){
        List<PlaceClassroom> list=classroomService.queryClassroom();
        if (list==null){
            return ResultUtils.Failure("查询教室信息失败",null);
        }else {
            return ResultUtils.Successful("查询教室信息成功",list);
        }
    }

    //删除教室
    @PostMapping("/deleteClassroom")
    public ResultUtils deleteClassroom(int classroomId){
        int res=classroomService.deleteClassroom(classroomId);
        if (res==0){
            return ResultUtils.Failure("删除教室信息失败",null);
        }else {
            return ResultUtils.Successful("删除教室信息成功",null);
        }
    }

    //添加教室
    @PostMapping("/addClassroom")
    public ResultUtils addClassroom(@RequestBody Classroom classroom){
        int res=classroomService.addClassroom(classroom);
        if (res==0){
            return ResultUtils.Failure("添加教室信息失败",null);
        }else {
            return ResultUtils.Successful("添加教室信息成功",null);
        }
    }

    @PostMapping("/queryIdClassroom")
    public ResultUtils queryIdClassroom(int placeId){
        List<IdClassroom> classroom= classroomService.queryIdClassroom(placeId);
        if (classroom.size()==0){
            return ResultUtils.Failure("根据教学点查询教室信息失败",null);
        }else {
            return ResultUtils.Successful("根据教学点查询教室信息成功",classroom);
        }
    }

    //对课室进行模糊查询
    @PostMapping("/fuzzyClassroom")
    public ResultUtils fuzzyClassroom(String classroomName){
        List<PlaceClassroom> classroomList= classroomService.fuzzyClassroom(classroomName);
        if (classroomList.size()==0){
            return ResultUtils.Failure("搜索课室失败或无该课室",null);
        }else {
            return ResultUtils.Successful("搜索课室成功",classroomList);
        }
    }
}
